// pages/Tax/TaxResult/TaxResult.js
var tax = require("../TaxAlgorithm.js").tax; 
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var displayObj={
          Val:false,
          isTax:false,
          isFirst:false,
          rate:false,
          loan:false,
          nFee:false,
          stampTax:false,
          regFee:false,
          sumFee:false,
          floor:false,
          tg_fee:false
      }
      /*
result.reg
result.isFirst
result.isStamp
result.rate
result.loanFee
result.floorFee
result.nFee
result.stampTax
result.regFee
result.nSum
      
      
       */
      var resultObj={
        reg:100,
        isFirst: true,
        isStamp: false,
        loanFee: 10,
        floorFee: 10,
        nFee: 10,
        stampTax: 10,
        regFee: 12,
        nSum: 11,
        rate:0,
        tg_fee:0
      };
      
      var result=wx.getStorageSync("taxResult");
      var tip="";
      console.log(result);


  
      if (result.tax_type =="tax-type-buy"){
         tip =" 計算買賣費用";
         displayObj.Val=true;
         displayObj.isTax = true;
         displayObj.isFirst = true;
         displayObj.nFee = true;
         displayObj.stampTax = true;
         displayObj.regFee = true;
         displayObj.sumFee = true;
         displayObj.tg_fee=true;
         resultObj.reg = tax.taxTools.toThousands(Math.ceil(result.txt_register)).replace(/,\./,"");
         resultObj.isFirst = result.isFirst==true?"是":"否";
         resultObj.isStamp = result.isStamp==true?"是":"否";

         resultObj.nFee = tax.taxTools.toThousands(result.nFee);
         resultObj.stampTax = tax.taxTools.toThousands(result.realEstateStampTax);
         resultObj.regFee = tax.taxTools.toThousands(result.registerFee);
         resultObj.nSum = tax.taxTools.toThousands(result.sumFee);
         resultObj.tg_fee = tax.taxTools.toThousands(result.tg_fee);

      } else if (result.tax_type =="tax-type-buyAndMortgage"){
        tip = " 計算買賣及按揭費用";
        displayObj.Val = true;
        displayObj.isTax = true;
        displayObj.isFirst = true;
        displayObj.nFee = true;
        displayObj.stampTax = true;
        displayObj.regFee = true;
        displayObj.sumFee = true;
        displayObj.loan=true;
        displayObj.rate=true;
        displayObj.tg_fee=true;
        console.log("resultIs:",result);
        resultObj.reg = tax.taxTools.toThousands(Math.ceil(result.buyObj.txt_register));
        resultObj.isFirst = result.buyObj.isFirst == true ? "是" : "否";
        resultObj.isStamp = result.buyObj.isStamp == true ? "是" : "否";

        resultObj.nFee = tax.taxTools.toThousands(result.nFee);
        resultObj.stampTax = tax.taxTools.toThousands(result.sumTax);
        resultObj.tg_fee = tax.taxTools.toThousands(result.buyObj.tg_fee);
        resultObj.regFee = tax.taxTools.toThousands(result.registerFee);
        resultObj.nSum = tax.taxTools.toThousands(result.sumFee);

        resultObj.loanFee = tax.taxTools.toThousands(Math.ceil(result.mortgageObj.txt_loan));
        resultObj.rate = result.mortgageObj.txt_rate * 100;
        resultObj.nFee = tax.taxTools.toThousands(result.sumNFee);
        resultObj.regFee = tax.taxTools.toThousands(result.sumRegFee);
        resultObj.nSum = tax.taxTools.toThousands(result.sumFee);




      } else if (result.tax_type == "tax-type-mortgage"){
        tip = " 計算按揭費用";
        displayObj.nFee = true;
        displayObj.regFee = true;
        displayObj.sumFee = true;
        displayObj.loan = true;
        displayObj.rate = true;
      //loanFee rate
     
        resultObj.loanFee = result.txt_loan;
        resultObj.rate = result.txt_rate*100;
        resultObj.nFee = tax.taxTools.toThousands(result.mortgageNFee);
        resultObj.regFee = tax.taxTools.toThousands(result.mortgageRegFee);
        resultObj.nSum = tax.taxTools.toThousands(result.sumFee);

      } else if (result.tax_type =="tax-type-register"){
        tip = " 計算臨時登記費用";
        displayObj.floor = true;
        displayObj.regFee = true;

        resultObj.floorFee = tax.taxTools.toThousands(result.txt_floor);
        resultObj.regFee = tax.taxTools.toThousands(result.tmpRegisterFee);
      }

      this.setData({
        display: displayObj,
        result: resultObj,
        tip: tip
      });

      /* 

      tax_type: "tax-type-buy",
      txt_register: txt_register,
      realEstateStampTax: realEstateStampTax,
      registerFee: registerFee,
      nFee: nFee,
      sumFee: sumFee

      tax_type: "tax-type-buyAndMortgage",
      sumNFee: sumNFee,
      sumTax: sumTax,
      sumFee: sumFee,
      sumRegFee: sumRegFee,
      mortgageObj: mortgageObj,
      buyObj: buyObj

      tax_type: "tax-type-mortgage",
      txt_loan: txt_loan,
      txt_rate: txt_rate,
      mortgageNFee: mortgageNFee,
      mortgageRegFee: mortgageRegFee,
      rate_fee: rate_fee,
      sumFee: sumFee

      tax_type: "tax-type-register",
      tmpRegisterFee: tmpRegisterFee,
      txt_floor: txt_floor
      
      
      
      */






  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})